#include "login.h"


Login::Login()
{
	ui = new Ui_Dialog();
	ui->setupUi(this);
	/* cancel button与Dialog close关联 */
	QObject::connect(ui->cancel , SIGNAL(clicked()),
		this , SLOT(login()));
	/* login button 与 自定义槽函数关联 */
	QObject::connect(ui->login , SIGNAL(clicked()),
		this , SLOT(login()));	
}

Login::~Login()
{
	delete(ui);
}

void Login::login()
{
	/* 区分信号发送对象，这里需要区分login和cancel的按钮对象 */
	if(((QPushButton *)sender())->objectName() == "login")
	{
		if(!QString::compare(ui->username->text(),"abc",Qt::CaseSensitive) && 
			!QString::compare(ui->password->text(),"123",Qt::CaseSensitive))
		{
			//std::cout<<"login success"<<std::endl;
			//qDebug("login success");
			QMessageBox msg(this);
			msg.setText("login success");
			msg.exec();
		}
		else
		{
			//std::cout<<"login failed"<<std::endl;
			qDebug("login failed");			
		}
	}
	
	if(((QPushButton *)sender())->objectName() == "cancel")
	{
		QMessageBox msg(this);
		msg.setText("Are you quit?");
		msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
		
		if(msg.exec() == QMessageBox::Yes)
		{
			this->close();
		}
	}
}








